package com.kedi.welfarecenter.controller.operationcenter;

import com.kedi.welfarecenter.enums.ResultEnum;
import com.kedi.welfarecenter.exception.CommonException;
import com.kedi.welfarecenter.service.operationcenter.MedicalPenFuseService;
import com.kedi.welfarecenter.utils.ResultVoUtil;
import com.kedi.welfarecenter.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Description:    医养融合控制层
* @Author:         ytw
* @CreateDate:     2019/7/23 15:59
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
@RestController
public class MedicalPenFuseController {
    private static Logger logger = LoggerFactory.getLogger(MedicalPenFuseController.class);
    @Autowired
    MedicalPenFuseService medicalPenFuseService;

    /**
    * 方法实现说明  查询所有医养融合数据
    * @author      ytw
    *@param
    * @return
    * @exception
    * @date        2019/7/24 15:20
    */
    @GetMapping("operation/medicalpenfuseList")
    public List<Map<String,Object>> getFuseList(){
        List<Map<String, Object>> list = medicalPenFuseService.selectoldlifeservice();
        if(list.isEmpty()){
            logger.info("查找所有养老服务补贴列表为空");
            throw new CommonException(ResultEnum.LIST_NOT_EXISTED);
        }else{
            return list;
        }
    }


    /**
    * 方法实现说明  创建 医养融合
    * @author      ytw
    *@param         name,visttime,vistcontent,servicestreet
    * @return
    * @exception
    * @date        2019/7/24 18:26
    */
    @PostMapping("operation/createmedicalpenfuse")
    public ResultVo createMedicalPenFuse(@RequestParam("name")String name, @RequestParam("visttime")String visttime,@RequestParam("vistcontent")String vistcontent,
                                         @RequestParam("servicestreet")String servicestreet){
        if(name==null){
            throw new CommonException(ResultEnum.PARAMETER_EXISTED);
        }else{
        Integer oldlifeid = medicalPenFuseService.findbyoldlifename(name);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("name",name);
        map.put("vist_time",visttime);
        map.put("vist_content",vistcontent);
        map.put("service_street",servicestreet);
        map.put("oldlife_id",oldlifeid);
        if(oldlifeid!=null){
            medicalPenFuseService.createMedicalPenFuse(map);
            return  ResultVoUtil.success();
        }else{
            medicalPenFuseService.createMedicalPenFuseAndOldlife(map);
            medicalPenFuseService.createMedicalPenFuse(map);
            return ResultVoUtil.success();
        }
    }}
}
